<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript">
$(function() {
    
    var tenderId = '${tenderId}';
    var memberLoginName = '${memberLoginName}';
    var tenderQuote = {};
	
	//for debug
	try{throw ''} catch(e){}
	
	accounting.settings.currency.format = {
      	pos : "%v",
      	zero: "0.00"
    };
	
	$('#quote_detail_grid').datagrid({
	    url: '${pageContext.request.contextPath}/api/QuoteDetailAPI.json',
	    columns: [[
            {field:'product_name', title:'产品名称', width:240, align:'left', halign:'center', resizable:false},
            {field:'quantity', title:'数量', width:75, align:'right', halign:'center', resizable:false},
            {field:'unit', title:'单位', width:75, align:'center', halign:'center', resizable:false},
            {field:'unit_price', title:'单价', width:150, align:'right', halign:'center', resizable:false, formatter: function(value, row, index) {
                return accounting.formatMoney(value);
            }},
            {field:'total_price', title:'合计', width:150, align:'right', halign:'center', resizable:false, formatter: function(value, row, index) {
                return accounting.formatMoney(value);
            }}
        ]],
        fit: true,
        striped: true,
        rownumbers: true,
        autoRowHeight: false,
        idField: 'product_id',
        onSelect: function(index, row) {
            $("#quote_detail_grid").datagrid('unselectRow', index);
        },
		loadFilter: function(data) {
		    var datax = {};
		    if (data.tender_quote) {
		        tenderQuote = data.tender_quote;
		    }
			if (data && data.quote_detail && $.isArray(data.quote_detail)) {
			    datax.total = data.quote_detail.length;
			    datax.rows = data.quote_detail;
			} else {
			    datax.total = 0;
            	datax.rows = new Array();
			}
	        return datax;
	    },
	    onLoadSuccess: function(date) {
	        $('#quote_detail_comment').text(tenderQuote.comment);
	        if (tenderQuote && tenderQuote.tender_doc) {
	            $('#btn_quote_detail_download').linkbutton('enable');
	        } else {
	            $('#btn_quote_detail_download').linkbutton('disable');
	        }
	        $('#btn_quote_detail_download').linkbutton({
                onClick: function() {
                    window.location.href = "${pageContext.request.contextPath}/file/AttachmentDownload.action?attachmentId=" + tenderQuote.tender_doc;
                }
            });
	    },
		queryParams: {
        	param: JSON.stringify({
        		tender_id: tenderId,
        		member_login_name: memberLoginName
        	})
        }
	});
});
</script>
<div style="width: 100%; height: 200px;">
  <table id="quote_detail_grid"></table>
</div>
<div style="width: 100%; margin-top: 10px;">
  <p>报价说明：</p>
  <p id="quote_detail_comment" style="margin-top: 5px;"></p>
</div>
<div style="width: 100%; text-align: right; margin: 20px 0 5px 0;">
  <a id="btn_quote_detail_download" href="#" class="easyui-linkbutton" style="margin-left:10px;" data-options="iconCls: 'icon-download', disabled: true">下载标书</a>
</div>